@extends('admin.main')

@section('content')
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <h5>个人资料</h5>
        </div>
        <div class="ibox-content">
            <form id="formProfile" method="post" class="form-horizontal">
                <div class="row">
                    <div class="col-md-8">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">帐户</label>
                            <div class="col-sm-6">
                                <input type="text" value="{{$user->username}}" class="form-control" readonly="" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">昵称</label>
                            <div class="col-sm-6">
                                <input type="text" name="nickname" value="{{$user->nickname}}" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">邮箱</label>
                            <div class="col-sm-8">
                                <input type="email" name="email" value="{{$user->email}}" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">手机</label>
                            <div class="col-sm-6">
                                <input type="text" name="mobile" value="{{$user->mobile}}" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">性别</label>
                            <div class="col-sm-8">
                                <label class="m-r-lg">
                                    <select name="sex" class="form-control">
                                        <option value="男"{{$user->sex == '男' ? ' selected ' : ''}}>男</option>
                                        <option value="女"{{$user->sex == '女' ? ' selected' : ''}}>女</option>
                                        <option value="保密"{{$user->sex == '保密' ? ' selected' : ''}}>保密</option>
                                    </select>
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">地区</label>
                            <div class="col-sm-3">
                                <select name="prov" class="form-control province"></select>
                            </div>
                            <div class="col-sm-3">
                                <select name="city" class="form-control city"></select>
                            </div>
                            <div class="col-sm-3">
                                <select name="dist" class="form-control district"></select>
                            </div>
                        </div>
                    </div>
           <!--          <div class="col-md-4">
                        <a href="javascript:;" id="btnChangeAvatar" title="点击修改头像">
                            <img src="{{$user->avatar}}" class="img-thumbnail" />
                        </a>
                    </div> -->
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <div class="col-sm-2 col-sm-offset-2">
                        <button type="submit" class="btn btn-warning btn-w-m">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection

@section('pagescript')
<script src="//cdn.bootcss.com/swfobject/2.2/swfobject.min.js"></script>
<script src="/assets/js/stringExt.js"></script>
<script src="/assets/js/jsAddress.js"></script>
<script>
    var artDialog;
    var uploadAvatar = function(data){
        if(data.status == "1"){
            var timenow = Math.ceil(new Date().getTime() / 1000);
            var src = data.url+'?'+timenow;
            $("#btnChangeAvatar").find('img').attr('src', src);
            layer.close(artDialog);
        }else{
            alert(data.info);
        }
    };

    seajs.use('models/userModel', function(userModel) {
        var loadFaustCplus = function(){
            var img_src = $("#btnChangeAvatar").find("img").eq(0).attr('src');
            var flashvars = {
                "jsfunc": "uploadAvatar",
                "imgUrl": img_src,
                "uploadSrc": true,
                "showBrow": true,
                "showCame": true,
                "pSize": "300|300|180|180|80|80",
                "uploadUrl": "{{url('admin/user/upload-avatar/'.$user->id)}}"
            };
            var params = {
                menu: "false",
                scale: "noScale",
                allowFullscreen: "true",
                allowScriptAccess: "always",
                wmode:"transparent",
                bgcolor: "#FFFFFF"
            };
            var attributes = {'id':"FaustCplus"};
            swfobject.embedSWF("/assets/iemaker/FaustCplus.swf", "flashContent", "650", "450", "10.1.0", null, flashvars, params, attributes);
            swfobject.createCSS("#flashContent", "display:block;text-align:left;");
        };

        $("#btnChangeAvatar").on('click', function(){
            artDialog = layer.open({
                title: '编辑头像',
                content: '<div id="flashContent"></div>',
                success: function(){
                    setTimeout(function(){
                        loadFaustCplus();
                    }, 500);
                },
                area: ['690px', '540px'],
                btn: false,
                shadeClose: true,
            });
        });

        $("#formProfile").on("submit", function(){
            var formdata = $(this).serialize();
            userModel.setProfile(formdata, function(data){
                artInfo('修改成功！');
            }, failure);
            return false;
        });
    });

    $(function(){
        $("#side-menu li[rel='profile']").addClass("active")
            .find("ul").addClass("in")
            .find("li[rel='1']").addClass("active");

        addressInit('province', 'city', 'district', '{{$user->prov}}', '{{$user->city}}', '{{$user->dist}}');
    });
</script>
@endsection
